package com.yz.mcd.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.yz.mcd.BaseApplication;
import com.yz.mcd.base.bcl.BaseBean;
import com.yz.mcd.base.imp.BaseActivityImp;
import com.yz.mcd.base.imp.BaseBeanImp;
import com.yz.mcd.bean.UserInfoBean;
import com.yz.mcd.R;
import com.yz.mcd.model.UserInfoModel;

/**
 * Created by 辉 on 2017/4/12.
 */

public class Ac_register extends AppCompatActivity implements BaseActivityImp {

    String TAG="Ac_register";
    EditText register_phone_et;
    EditText register_rephone_et;
    EditText register_pw_et;
    EditText register_repw_et;
    UserInfoModel acUserInfoModel;
    Button re_login;


    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_register);

        acUserInfoModel=new UserInfoModel(this);

        TextView back_login_tv1=(TextView)findViewById(R.id.back_login_tv1);
        register_phone_et=(EditText)findViewById(R.id.register_phone_et);
        register_rephone_et=(EditText)findViewById(R.id.register_rephone_et);
        register_pw_et=(EditText)findViewById(R.id.register_pw_et);
        register_repw_et=(EditText)findViewById(R.id.register_repw_et);
        re_login=(Button)findViewById(R.id.re_login_bn);

        register_phone_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                register_phone_et.setTextColor(0xFFFFFFFF);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        register_rephone_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                register_rephone_et.setTextColor(0xFFFFFFFF);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        register_pw_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                register_pw_et.setTextColor(0xFFFFFFFF);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        register_repw_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                register_repw_et.setTextColor(0xFFFFFFFF);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        back_login_tv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v){
                finish();
            }
        });

        re_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UserInfoBean tmpBean=new UserInfoBean();
                if(getUserInfoBean(tmpBean)){
                    BaseApplication.cout(tmpBean.toString());
                    Log.e(TAG,tmpBean.toString());
                    BaseBean basemodelTemp=(BaseBean) tmpBean;
                    acUserInfoModel.handleInfo("Ac_reg_1",basemodelTemp);
                }
            }
        });
    }

    public boolean getUserInfoBean(UserInfoBean tmpBean){
        String pw,repw;
        pw=register_pw_et.getText().toString();
        repw=register_repw_et.getText().toString();
        if(!pw.equals(repw))
        {
            BaseApplication.cout(this.getString(R.string.passworddifferent));
            return false;
        }

        tmpBean.setPhone(register_phone_et.getText().toString());
        tmpBean.setPhoneCode(register_rephone_et.getText().toString());
        tmpBean.setUser_name(register_phone_et.getText().toString());
        tmpBean.setUser_pwd(pw);
        if(tmpBean.getPhone().equals("")||
                tmpBean.getPhoneCode().equals("")||
                tmpBean.getUser_name().equals("")){
            BaseApplication.cout(getString(R.string.info_no_full));
            return false;
        }
        return true;
    }


    public void infoChangeEvent(String type, BaseBeanImp bean){

        switch (type)
        {
            case "Ac_reg_1":
                BaseApplication.cout("XB");
                Log.e(TAG,"XBB");
                finish();
                break;
            case "Ac_reg_10":
                break;
        }
    }
}
